<?php

namespace App\Repositories\Eloquent\Admin;

use EasySwoole\ORM\AbstractModel;


class AdminOnlineModel extends AbstractModel
{
    protected $tableName = 'k_admin_online';
    protected $connectionName = 'wr';
    protected $autoTimeStamp = true;
    protected $createTime = 'add_time';
    protected $updateTime = 'update_time';


    public function getItemByAdminId(int $adminId = 0){
        return $this->create()->get(['id_admin'=>$adminId]);
    }

    public function getItemByAdminToken(string $token = ''){
         return $this->create()->get(['login_key'=>$token]);
    }

    public function getCountByAdminId(int $adminId = 0){
         return $this->create()->where(['id_admin'=>$adminId])->count();

    }
    public function delByAdminId(int $adminId = 0){
         $this->create()->destroy(['id_admin' => $adminId]);
    }

    public function createAdminOnline(array $data){
         $this->create($data)->save();
    }

    public function setOnlineActiveTime(int $adminId = 0){
        $obj = $this->create()->get(['id_admin'=>$adminId]);
        $obj->active_time = time();
        $obj->update();
    }



}